// subPages/communityService/healthService/healthService.js
// subPages/communityService/HomemakingService/HomemakingService.js
const app = getApp();
var utils = require('../../../utils/util');
var loadMoreView,p = 1,showNum = 4,type='service'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        selectIndex:0,
        array:["好评优先","距离优先","人气优先",""],
        bannerSet:{
            interval:5000,    //自动切换时间间隔
            duration:500,     //滑动动画时间长短
            autoplay:true,    //是否自动切换默认false
            circular:true,    //是否衔接切换
            indicatorDots:true,     //显示指示点
            indicatorColor:'rgba(255,255,255,.8)', //指示点颜色
            indicatorActiveColor:app.globalData.themeColor //当前指示点颜色
        },
        bannerStyle:{
            width:"100%",  //banner图宽
            height:"200rpx" //banner图高
        },
        bannerList:[],
        // selectorItems:['好评优先','距离优先'],
        iconNavList:[
            {
                background: '#ffbd3d',
                url:'/resources/communityService/bj.png',
                iconW: 37,
                iconH: 47,
                text: '保洁清洁',
                index: 1,
                link: "/subPages/communityService/homemakingServiceItem/homemakingServiceItem"
            },
            {
                background: '#00aeff',
                url:'/resources/communityService/xy.png',
                iconW: 49,
                iconH: 38,
                text: '衣物洗护',
                index: 2,
                link: "/subPages/communityService/homemakingServiceItem/homemakingServiceItem"
            },
            {
                background: '#ff3d9d',
                url:'/resources/communityService/grws.png',
                iconW: 46,
                iconH: 46,
                text: '个人卫生',
                index: 3,
                link: "/subPages/communityService/homemakingServiceItem/homemakingServiceItem"
            },
            {
                background: '#ff3d74',
                url:'/resources/communityService/ks.png',
                iconW: 43,
                iconH: 41,
                text: '上门开锁',
                index: 4,
                link:"/subPages/communityService/homemakingServiceItem/homemakingServiceItem"
            },
            {
                background: '#d43dff',
                url:'/resources/communityService/wx.png',
                iconW: 40,
                iconH: 40,
                text: '维修服务',
                index: 5,
                link:"/subPages/communityService/homemakingServiceItem/homemakingServiceItem"
            }
        ],
        homemakingServiceList:[]
    },
    makeCall(e){
        let phone = e.currentTarget.dataset.phone;
        wx.makePhoneCall({
            phoneNumber:phone
        })
    },
    goToDetails:function(e){
        let id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url:'/subPages/communityService/healthServiceDetails/healthServiceDetails?id='+id
        })
    },
    //图标导航路由
    iconNavBtn(e){
        let index = e.currentTarget.dataset.id;
        wx.navigateTo({
            url:'/subPages/communityService/homemakingServiceItem/homemakingServiceItem?type=1&id='+index
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        loadMoreView = this.selectComponent("#loadMoreView")
        utils.setNavBarTitle('健康服务');
        utils.setNavBarColor('#ffffff',app.globalData.themeColor);
        this.getBanner();
        this.getHealthServiceClass();
        this.getHealthServiceItems();
    },
    //获取分类
    getHealthServiceClass(){
        var that = this;
        utils.getAjax(`${app.globalData.apiUrl}/get_community_service_up_home_shop_class`,function(res){
            // console.log(res);
            for(var i in res.data){
                res.data[i].iconH = res.data[i].iconh;
                res.data[i].iconW = res.data[i].iconw;
                res.data[i].text = res.data[i].class_name;
            }
            that.setData({
                iconNavList:res.data
            })

        },{
        	community_id:app.globalData.communityId
        })
    },
    getBanner(){
        let that = this;
        utils.getAjax(`${app.globalData.apiUrl}/get_community_service_up_home_shop_banner`,function(res){
            // console.log(res);
            that.setData({
                bannerList:res.data
            })
        },{
            community_id:app.globalData.communityId
        })
    },
    getHealthServiceItems(){
        var that = this;
        utils.getAjax(`${app.globalData.apiUrl}/get_community_service_up_home_shop`,function(res){
            // console.log(res);
            if(res.data.list.length != 0){
                var list = [];
                if(p == 1){
                    list = res.data.list
                }else{
                    list = that.data.homemakingServiceList.concat(res.data.list)
                }
                that.setData({
                    homemakingServiceList:list
                })
            }else{
                that.setData({
                    homemakingServiceList:[]
                })
            }
            loadMoreView.loadMoreComplete(res.data,type)
        },{
            class_id:'',
            p:p,
            num:showNum,
            community_id:app.globalData.communityId
        })
    },
    //获取服务数据异常
    shopDataErr(err){
        let that = this;
        if(p>1){
            loadMoreView.loadMoreFail()
        }else{
            util.showModal('提示','获取商品失败，请向上滑动屏幕')
            this.setData({
                isFail: true
            })
        }
    },
    loadMoreListener: function(e) {
        p += 1
        this.getHealthServiceItems()
    },

    clickLoadMore: function(e) {
        this.getHealthServiceItems()
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        if(this.data.isFail){
            this.getHealthServiceItems();
            return
        }
        loadMoreView.loadMore()
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})
